import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Role} from './role.model';

@Injectable()
export class RoleService {
  constructor(private http: HttpClient) {
  }

  private url: string = '/api/role';

  private headers = new HttpHeaders({'Content-Type': 'application/json'});

  findAll() {
    return this.http.get(this.url + '/list', {headers: this.headers});
  }

  modify(role: Role): Promise<any> {
    return this.http.post(this.url + '/modify', {
      id: role.id,
      name: role.name,
      description: role.description,
      creator: role.creator,
      status: role.status
    }, {headers: this.headers}).toPromise();
  }


  delete(id: number): Promise<any> {
    return this.http.get(this.url + '/delete/' + id, {headers: this.headers}).toPromise();
  }
}
